import Vue from "vue"
import Vuex from 'vuex'
import persistedState from 'vuex-persistedstate'
Vue.use(Vuex)
 const store = new Vuex.Store({
	state: {
		userInfo:{
			
		},
		isLogin:false,
		
	},
	mutations: {
		login(state,parm){
			state.userInfo = parm
			state.isLogin = true
		},
		loginout(state){
			state.userInfo = {}
			state.isLogin = false
		}
	},
	actions: {
		getToken({commit}){
			//创建一个请求
			uni.request({
				url:"{登录的接口}",
				method:"POST",
				//账号，密码
				data:{"username":"admin","password":"admin123"},
				success(res) {					
					const {code,msg,token} = res.data
					//接口调用成功后 使用commit调用mutations里的函数并把token传过去					
						commit("settoken",token)
				}
			})
			
			
		}
	},
	getters: {
		count(state, getters) {
			return state.count
		},
		// testArr(state, getters) {
		// 	return state.testArr
		// },
	},
	plugins: [persistedState({
      key: 'erabbit-client-pc-store'
    })],
})

export default store